<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="管点编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pipPointNo">
              <a-input v-model="model.pipPointNo" placeholder="请输入管点编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管点名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pipPointName">
              <a-input v-model="model.pipPointName" placeholder="请输入管点名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="点位编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pointPosNo">
              <a-input v-model="model.pointPosNo" placeholder="请输入点位编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="液位计均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="liquid">
              <a-input-number v-model="model.liquid" placeholder="请输入液位计均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流量计均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowMeter">
              <a-input-number v-model="model.flowMeter" placeholder="请输入流量计均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="氨氮均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ammoNitr">
              <a-input-number v-model="model.ammoNitr" placeholder="请输入氨氮均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="ph均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ph">
              <a-input-number v-model="model.ph" placeholder="请输入ph均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="投入液位计均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="liquidTr">
              <a-input-number v-model="model.liquidTr" placeholder="请输入投入液位计均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报告时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reportTime">
              <j-date placeholder="请选择报告时间"  v-model="model.reportTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="均值类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avgType">
              <a-input-number v-model="model.avgType" placeholder="请输入均值类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="降雨量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rainData">
              <a-input-number v-model="model.rainData" placeholder="请输入降雨量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="cod均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cod">
              <a-input-number v-model="model.cod" placeholder="请输入cod均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电导率均值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="conduct">
              <a-input-number v-model="model.conduct" placeholder="请输入电导率均值" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'PaishuiPosRtdAvgHoursForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/posavghours/paishuiPosRtdAvgHours/add",
          edit: "/posavghours/paishuiPosRtdAvgHours/edit",
          queryById: "/posavghours/paishuiPosRtdAvgHours/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>